// File Process.java
// This Process class provides a process object.

 
public class Process implements Comparable
{
    private int arrivalTime;
    private int priority;
    private int timeRemaining;  
     // The number of time slices the process needs before it can be finished.
    private int timeNotProcessed;
     // The number of unit time has past since last time it got a time slice.


    public Process(int arrival, int level, int timeRequire)
    {
	arrivalTime = arrival;
	priority = level;
	timeRemaining = timeRequire;
	timeNotProcessed = 0;
    }

    // return 1 if this process should be processed before p.
    // return -1 otherwise.
    // the process with a higher priority gets processed first, 
    // in case of a tie use the process with an earlier arrival time. 
    // 
    public int compareTo(Object p)
    {
    	if (this.getPriority() > ((Process)p).getPriority())
    		return 1; // return 1 if this has a higher priority and should be processed before p 
    	if( this.getPriority() == ((Process)p).getPriority() && this.getArrivalTime() < ((Process)p).getArrivalTime())
   			return 1; // return 1 if this and p have the same priority, but this arrived sooner so it should be processed first
    	return -1; // return -1 to indicate that p should be processed before this  
    }

    public int getArrivalTime()
    {
	return arrivalTime;
    }

    public int getPriority()
    {
	return priority;
    }

    public int getTimeRemaining()
    {
	return timeRemaining;
    }
    
    public int getTimeNotProcessed()
    {
	return timeNotProcessed;
    }

    public void reduceTimeRemaining()
    {
	timeRemaining--;
    }

    public void increaseTimeNotProcessed()
    {
	timeNotProcessed++;
    }

    public void resetTimeNotProcessed()
    {
	timeNotProcessed = 0;
    }
    
    public boolean finish()
    {
	return (timeRemaining == 0);
    }
	    
    public void changePriority(int level)
    {
	priority = level;
    }
    
    public String toString()
    {
    	return ("[" + String.valueOf(arrivalTime) + ", " + String.valueOf(priority) + ", " + String.valueOf(timeRemaining) + "]");
    }
}
